﻿using System;
using HK.Core.Common;
using UnityEditor;

namespace HK.Editor.Utils
{
    
    /// <summary>
    /// 未知平台/渠道异常
    /// </summary>
    public class UnknownPlatformTypeException : NotImplementedException
    {
        public UnknownPlatformTypeException(PlatformType iPlatform) : 
            base($"Unknown Platform Type!(Platform:{iPlatform})") { }
    }
    
    /// <summary>
    /// 工具类 : 平台/渠道
    /// </summary>
    public static class UtilsPlatform
    {

        /// <summary>
        /// 转换成Build Target
        /// </summary>
        /// <param name="iPlatform">平台/渠道</param>
        /// <returns>Build Target</returns>
        /// <exception cref="UnknownPlatformTypeException">未知平台/渠道异常</exception>
        public static BuildTarget ConvertToBuildTarget(PlatformType iPlatform)
        {
            var buildTarget = BuildTarget.NoTarget;

            switch (iPlatform)
            {
                case PlatformType.IOS:
                    buildTarget = BuildTarget.iOS;
                    break;
                case PlatformType.Android:
                case PlatformType.Huawei:
                case PlatformType.Bilibili:
                case PlatformType.Tabtap:
                    buildTarget = BuildTarget.Android;
                    break;
                case PlatformType.Ps4:
                    buildTarget = BuildTarget.PS4;
                    break;
                case PlatformType.Ps5:
                    buildTarget = BuildTarget.PS5;
                    break;
                case PlatformType.XboxOne:
                    buildTarget = BuildTarget.XboxOne;
                    break;
                case PlatformType.StandaloneWindows:
                    buildTarget = BuildTarget.StandaloneWindows;
                    break;
                case PlatformType.StandaloneWindows64:
                    buildTarget = BuildTarget.StandaloneWindows64;
                    break;
                default:
                    throw new UnknownPlatformTypeException(iPlatform);
            }
            
            return buildTarget;
        }
        
        /// <summary>
        /// 转换成Build Group Target
        /// </summary>
        /// <param name="iPlatform">平台/渠道</param>
        /// <returns>Build Target</returns>
        /// <exception cref="UnknownPlatformTypeException">未知平台/渠道异常</exception>
        public static BuildTargetGroup ConvertToBuildGroupTarget(PlatformType iPlatform)
        {
            var buildTarget = BuildTargetGroup.Unknown;

            switch (iPlatform)
            {
                case PlatformType.IOS:
                    buildTarget = BuildTargetGroup.iOS;
                    break;
                case PlatformType.Android:
                case PlatformType.Huawei:
                case PlatformType.Bilibili:
                case PlatformType.Tabtap:
                    buildTarget = BuildTargetGroup.Android;
                    break;
                case PlatformType.Ps4:
                    buildTarget = BuildTargetGroup.PS4;
                    break;
                case PlatformType.Ps5:
                    buildTarget = BuildTargetGroup.PS5;
                    break;
                case PlatformType.XboxOne:
                    buildTarget = BuildTargetGroup.XboxOne;
                    break;
                case PlatformType.StandaloneWindows:
                case PlatformType.StandaloneWindows64:
                    buildTarget = BuildTargetGroup.Standalone;
                    break;
                default:
                    throw new UnknownPlatformTypeException(iPlatform);
            }
            
            return buildTarget;
        }
        
    }
}